<!--
 * Description: FD Detail 组件(FD查看)
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/06/10 16:15
-->

<template>
  <div class="fd-detail">
    <!--TODO: 设置用户的习惯按钮 -->
    <el-tooltip class="item" content="自定义表格显示列" effect="dark" placement="top">
      <button class="set-fd-cell" @click="setDialogVisible = true"></button>
    </el-tooltip>
    <div class="custom-top">
      <div class="total-result">
        <table>
          <tr>
            <td>总行数：{{ totalResult.totalLen }}</td>
            |
            <td>当前行数：{{ totalResult.currentLen }}</td>
            |
            <td>Cost Down：{{ totalResult.costDown }}</td>
          </tr>
        </table>
      </div>
    </div>
    <div class="custom-bottom">
      <VirtualTable
        :cb="totalCb"
        cbArgs="costDown"
        :filterable="true"
        :header-cell-style="$headerCellStyle"
        :rowStyle="rowStyle"
        rowKey="fdRowId"
        :table="shareDataList"
      >
        <!-- rowNo -->
        <Cell fix="left" :label="$t('ecdfc.rowNo')" :width="50">
          <template slot-scope="scope">
            <span>{{ scope.index + 1 }}</span>
          </template>
        </Cell>
        <!-- rdFunction -->
        <Cell
          v-if="cellIsShow.IsRDFunction"
          :label="$t('ecdfc.rdFunction')"
          prop="rdFunction"
          sort
        />
        <!-- category -->
        <Cell v-if="cellIsShow.IsCategory" :label="$t('ecdfc.category')" prop="category" sort />
        <!-- fdDesign -->
        <Cell v-if="cellIsShow.IsFdDesign" :label="$t('ecdfc.fdDesign')" prop="fdDesign" sort />
        <!-- Old -->
        <Cell :label="$t('ecdfc.old')">
          <!-- oldPn -->
          <Cell v-if="cellIsShow.IsOldPn" :label="$t('ecdfc.pn')" prop="oldPn" sort />
          <!-- oldQty -->
          <Cell v-if="cellIsShow.IsOldQty" :label="$t('ecdfc.qty')" prop="oldQty" sort />
        </Cell>
        <!-- New -->
        <Cell :label="$t('ecdfc.new')">
          <!-- newPn -->
          <Cell v-if="cellIsShow.IsNewPn" :label="$t('ecdfc.pn')" prop="newPn" sort="number" />
          <!-- newQty -->
          <Cell v-if="cellIsShow.IsNewQty" :label="$t('ecdfc.qty')" prop="newQty" sort="number" />
        </Cell>
        <!-- riskImpact -->
        <Cell
          v-if="cellIsShow.IsRiskImpact"
          :label="$t('ecdfc.riskImpact')"
          prop="riskImpact"
          sort="number"
        />
        <!-- deadline -->
        <Cell
          v-if="cellIsShow.IsDeadline"
          :label="$t('ecdfc.deadline')"
          prop="deadline"
          sort="number"
        />
        <!-- plan -->
        <Cell v-if="cellIsShow.IsPlan" :label="$t('ecdfc.plan')" prop="plan" sort />
        <!-- subject -->
        <Cell v-if="cellIsShow.Issubject" :label="$t('ecdfc.subject')" prop="subject" sort />
        <!-- commodity -->
        <Cell v-if="cellIsShow.Iscommodity" :label="$t('ecdfc.commodity')" prop="commodity" sort />
        <!-- assignedTime -->
        <Cell
          v-if="cellIsShow.IsassignedTime"
          :label="$t('ecdfc.assignedTime')"
          prop="assignedTime"
          sort
        />
        <!-- isAssigned -->
        <Cell v-if="cellIsShow.IsisAssigned" :label="$t('ecdfc.isAssigned')" prop="isAssigned" sort>
          <template slot-scope="scope">
            <span>{{ scope.row.isAssigned ? 'Y' : 'N' }}</span>
          </template>
        </Cell>
        <!-- isGcmCommit -->
        <Cell
          v-if="cellIsShow.IsisGcmCommit"
          :label="$t('ecdfc.isGcmCommit')"
          prop="isGcmCommit"
          sort
        >
          <template slot-scope="scope">
            <span>{{ scope.row.isGcmCommit ? 'Y' : 'N' }}</span>
          </template>
        </Cell>
        <!-- isGcmReject -->
        <Cell
          v-if="cellIsShow.IsisGcmReject"
          :label="$t('ecdfc.isGcmReject')"
          prop="isGcmReject"
          sort
        >
          <template slot-scope="scope">
            <span>{{ scope.row.isGcmReject ? 'Y' : 'N' }}</span>
          </template>
        </Cell>
        <!-- owner -->
        <Cell v-if="cellIsShow.IsOwner" :label="$t('ecdfc.owner')" prop="owner" sort />
        <!-- initialDate -->
        <Cell
          v-if="cellIsShow.IsInitialDate"
          :label="$t('ecdfc.initialDate')"
          prop="initialDate"
          sort="number"
        />
        <!-- closeDate -->
        <Cell
          v-if="cellIsShow.IsCloseDate"
          :label="$t('ecdfc.closeDate')"
          prop="closeDate"
          sort="number"
        />
        <!-- svtBomStatus -->
        <Cell
          v-if="cellIsShow.IsSvtBomStatus"
          :label="$t('ecdfc.svtBomStatus')"
          prop="svtBomStatus"
          sort="number"
        />
        <!-- rdForecastCost -->
        <Cell
          v-if="cellIsShow.IsRdForecastCost"
          :label="$t('ecdfc.rdForecastCost')"
          prop="rdForecastCost"
          sort="number"
        />
        <!-- costDown -->
        <Cell
          v-if="cellIsShow.IsCostDown"
          :label="$t('ecdfc.costDown')"
          prop="costDown"
          sort="number"
        />
        <!-- apprvoal -->
        <Cell v-if="cellIsShow.IsApprvoal" :label="$t('ecdfc.apprvoal')" prop="apprvoal" sort />
        <!-- remark -->
        <Cell v-if="cellIsShow.IsRemark" :label="$t('ecdfc.remark')" prop="remark" />
        <!-- gcm -->
        <Cell :label="$t('FdData.gcm')">
          <!-- gcmFunction -->
          <Cell
            v-if="cellIsShow.IsGcmFunction"
            :label="$t('FdData.gcmFunction')"
            prop="gcmFunction"
            sort="number"
          />
          <!-- GcmOwner -->
          <Cell v-if="cellIsShow.IsGcmOwner" :label="$t('FdData.gcmOwner')">
            <template slot-scope="scope">
              {{ gcmOwnerById(scope.row.gcmOwner) }}
            </template>
          </Cell>
          <!-- gcmCostRemark -->
          <Cell
            v-if="cellIsShow.IsGcmCostRemark"
            :label="$t('FdData.gcmCostRemark')"
            prop="gcmCostRemark"
          />
        </Cell>
      </VirtualTable>
    </div>

    <!--图片对话框-->
    <BaseDialog
      v-if="picDialogVisible"
      title="图片查看"
      :visible.sync="picDialogVisible"
      width="35%"
    >
      <BaseIdpPicView
        :idp-token="idpToken"
        :pic-list="picList"
        @cancel="picDialogVisible = false"
      />
    </BaseDialog>
    <!--TODO: 设置显示列对话框 -->
    <BaseDialog
      v-if="setDialogVisible"
      title="设置显示列"
      :visible.sync="setDialogVisible"
      width="50%"
    >
      <EcCellShowSet
        :cellIsShow="cellIsShow"
        :pageId="pageId"
        @cancel="setDialogVisible = false"
        @saveOperationData="saveOperationData"
      />
    </BaseDialog>
  </div>
</template>
<script>
import { idpGetToken } from '@/api/quote/idp'
// import { fdRowPictureList } from '@/api/quote/fd-row-picture'
import Cell from '@/widgets/VirtualTable/Cell'
import VirtualTable from '@/widgets/VirtualTable/Table'
import ecCell from '@/mixins/ecCell'
import EcCellShowSet from '../../components/EcCellShowSet'
export default {
  name: 'EcDetail',

  components: { VirtualTable, Cell, EcCellShowSet },
  mixins: [ecCell],

  props: {
    inputData: {
      default: () => null,
      type: Object
    },
    isCompare: {
      type: Boolean,
      default: false
    },
    shareDataList: {
      default: () => [],
      type: Array
    }
  },
  data() {
    return {
      // idp token
      idpToken: '',
      // 每一行的图片数据
      picList: [],
      // 图片对话框可见标识
      picDialogVisible: false,
      // 合计信息
      totalResult: {
        totalLen: 0,
        currentLen: 0,
        costDown: 0
      },
      setDialogVisible: false,
      pageId: 'EcApproveView',
      cellIsShow: {}
    }
  },
  computed: {
    gcmOwnerById() {
      return gcmOwner => {
        if (gcmOwner && gcmOwner.length) {
          return this.$store.getters['user/getUserNameById'](gcmOwner)
        } else {
          return ''
        }
      }
    }
  },
  mounted() {
    this.pageDataInit()
  },
  methods: {
    /* eslint-disable */

    rowStyle(index, row) {
      return row.isRelateRow
        ? {
            backgroundColor: '#cee6ff'
          }
        : {
            backgroundColor: '#fff'
          }
    },
    pageDataInit() {
      this.getIdpGetToken()
    },
    async getIdpGetToken() {
      try {
        const idpTokenRes = await idpGetToken({})
        this.idpToken = idpTokenRes.data.accessToken
      } catch (error) {
        console.log(error)
      }
    },

    // 查看fd每一行图片列表
    // async fdPicList(data, isNew) {
    //   const res = await fdRowPictureList({ fdRowId: data.fdRowId, isNew: isNew })
    //   this.picList = res.data
    //   this.picDialogVisible = true
    // },
    totalCb(args) {
      this.totalResult = { ...args }
    }
  }
}
</script>
<style lang="scss" scoped>
.fd-detail {
  .custom-top {
    width: calc(100% - 17px);
    height: 42px;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
  }
}
</style>
